package com.xin.di.uav.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xin.di.uav.user.entity.UserExtra;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 用户额外信息表 Mapper 接口
 * </p>
 *
 * @author LTQ
 * @since 2023-06-14
 */
@Mapper
public interface UserExtraMapper extends BaseMapper<UserExtra> {


    @Select({"<script>",
            "select user_id,last_login_time from user_extra where user_id  in  " +
                    "<foreach collection='userIds' item='userId' open='(' close=')' separator=','>",
            "#{userId}",
            "</foreach>",
            "</script>"})
    List<UserExtra> selByUserIds(@Param("userIds") List<String> userIds);


    @Update({
            "<script>",
            "UPDATE user_extra ",
            "<set>",
            "    <if test='receiveName != null'>receive_name = #{receiveName},</if>",
            "    <if test='receivePhone != null'>receive_phone = #{receivePhone},</if>",
            "    update_time = NOW()",

            "</set>",
            "WHERE user_id = #{userId}",
            "</script>"
    })
    int updateAddress(UserExtra userExtra);


    @Select({"<script>",
            "select user_id,last_login_time,receive_phone,receive_name from user_extra where user_id =#{userId} " +
            "</script>"})
    UserExtra selByUserId(@Param("userId") String userId);


}
